package br.inf.solutions.apresentacoes.ssp.control;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import br.com.vexillum.model.IActivatedEntity;
import br.com.vexillum.util.Return;
import br.inf.solutions.apresentacoes.ssp.model.Weapon;

@Service
@Scope("prototype")
public class WeaponController extends BaseController<Weapon>{

	public WeaponController() {
		super(Weapon.class);
	}
	
	@Override
	public Return listAll() {
		String sql = "FROM " + classEntity.getSimpleName() + " WHERE active = true";
		if(data.get("entity") == null || (((IActivatedEntity) data.get("entity")).getActive() == null) || !((IActivatedEntity) data.get("entity")).getActive()){
			sql = sql.replace(" WHERE active = true", "");
		}
		data.put("sql", sql);
		return super.searchByHQL();
	}
		
	public Return searchWeapon() {
		Return ret = new Return(true);		
		String sql = "FROM " + classEntity.getSimpleName() + " WHERE numberWeapon = '" + entity.getNumberWeapon() + "' AND active = true";
		data.put("sql", sql);
		ret.concat(searchByHQL());
		return ret;
	}
}